package pers.vic.base.bo.system;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;



/**
 * 菜单表
 * 
 * @author VIC
 */
public class SysMenu implements Serializable, Comparable<SysMenu> {

	private static final long serialVersionUID = 1L;

	/**
	 * 主键,手动新增吧;1;
	 */
	private Integer id;
	/**
	 * 名称;1;
	 */
	private String name;
	/**
	 * 所属父类;1;
	 */
	private Integer pid;
	/**
	 * 排序字段;1;
	 */
	private Integer sort;
	/**
	 * url,以/开头;1;
	 */
	private String url;
	/**
	 * 图标;1;
	 */
	private String label;
	/**
	 * 权限，一般作为按钮时候使用;1
	 */
	private String permission;
	/**
	 * 类别;1;1-模块,2-菜单,3-按钮;
	 */
	private Integer type;
	/**
	 * 是否删除;1;
	 */
	private Boolean isDelete;

	/* ***********************************************************************/
	// 角色和菜单关系id
	private Integer relId;

	private Boolean checked;

	private String iconSkin;// 自定义图标

	/* ***********************************************************************/

	/**父级菜单*/
	private SysMenu parent;
	
	/**子菜单*/
	private List<SysMenu> children = new ArrayList<SysMenu>();	
	
	/**添加子菜单*/
	public void  addChildren(SysMenu menu){
		this.children.add(menu);
		menu.setParent(this);
	}
	
	
	@Override
	public int compareTo(SysMenu o) {
		if(o == null ) {
			return -1;
		}
		if(o.getPid().equals(this.getPid())){//如果两个同属于一级则判断 sort
			return this.sort - o.sort;
		}
		return this.getId()-o.getId() ;
	}
		
	
	
	/**当前菜单是根节点吗*/
	public boolean isRoot(){
		return this.pid == null || this.pid == 0;
	}
	
	/**
	 * set：主键,手动新增吧;1;
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * get：主键,手动新增吧;1;
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * set：名称;1;
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * get：名称;1;
	 */
	public String getName() {
		return name;
	}

	/**
	 * set：所属父类;1;
	 */
	public void setPid(Integer pid) {
		this.pid = pid;
	}

	/**
	 * get：所属父类;1;
	 */
	public Integer getPid() {
		return pid == null ? 0 : pid;
	}

	/**
	 * set：排序字段;1;
	 */
	public void setSort(Integer sort) {
		this.sort = sort;
	}

	/**
	 * get：排序字段;1;
	 */
	public Integer getSort() {
		return sort;
	}

	/**
	 * set：url,以/开头;1;
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	/**
	 * get：url,以/开头;1;
	 */
	public String getUrl() {
		return url;
	}

	/**
	 * set：图标;1;
	 */
	public void setLabel(String label) {
		this.label = label;
	}

	/**
	 * get：图标;1;
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * set：权限，一般作为按钮时候使用;1
	 */
	public void setPermission(String permission) {
		this.permission = permission;
	}

	/**
	 * get：权限，一般作为按钮时候使用;1
	 */
	public String getPermission() {
		return permission;
	}

	/**
	 * set：类别;1;1-模块,2-菜单,3-按钮;
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * get：类别;1;1-模块,2-菜单,3-按钮;
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * set：是否删除;1;
	 */
	public void setIsDelete(Boolean isDelete) {
		this.isDelete = isDelete;
	}

	/**
	 * get：是否删除;1;
	 */
	public Boolean getIsDelete() {
		return isDelete;
	}

	public Integer getRelId() {
		return relId;
	}

	public void setRelId(Integer relId) {
		this.relId = relId;
	}

	public Boolean getChecked() {
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}

	public String getIconSkin() {
		if (StringUtils.isNoneBlank(iconSkin)) {
			return iconSkin;
		}
		if (this.type == 3) {
			return "icon02";
		} else {
			return "pIcon01";
		}
	}
	

	public void setIconSkin(String iconSkin) {
		this.iconSkin = iconSkin;
	}

	public List<SysMenu> getChildren() {
		return children;
	}

	public void setChildren(List<SysMenu> children) {
		this.children = children;
	}

	public SysMenu getParent() {
		return parent;
	}

	public void setParent(SysMenu parent) {
		this.parent = parent;
	}
	
	
	
	

}
